package com.itrip.service.impl;

import com.itrip.dao.ItripHotelOrderMapper;
import com.itrip.dao.ItripHotelTempStoreMapper;
import com.itrip.dao.ex.HotelMapper;
import com.itrip.document.Hotel;
import com.itrip.dto.HotelDetail;
import com.itrip.pojo.ItripHotelOrder;
import com.itrip.pojo.ItripHotelTempStore;
import com.itrip.repository.HotelRepository;
import com.itrip.service.HotelService;
import org.apache.solr.client.solrj.SolrServerException;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@Service
public class HotelServiceImpl implements HotelService {

    @Resource
    private ItripHotelTempStoreMapper itripHotelTempStoreMapper;

    @Resource
    private HotelRepository hotelRepository;

    @Resource
    private HotelMapper hotelMapper;

    @Resource
    private ItripHotelOrderMapper itripHotelOrderMapper;

    @Override
    @Cacheable(value = {"getHotel"})
    public List<Hotel> getHotel(String keyWord, int i, Integer pageSize) throws IOException, SolrServerException {
        return hotelRepository.getHotel(keyWord,i,pageSize);
    }

    @Override
    public int getHotelNum(String keyWord) throws IOException, SolrServerException {
        return hotelRepository.getHotelNum(keyWord);
    }

    @Override
    @Cacheable(value = {"getHotelDetail"})
    public List<HotelDetail> getHotelDetail(Integer id) {
        return hotelMapper.getHotelDetail(id);
    }

    @Override
    @CacheEvict(value = "getHotel",allEntries = true)
    public void clear() {

    }

    @Override
    public int getRestRoom(Integer hotelId, Integer roomId) {
        return hotelMapper.getRestRoom(hotelId,roomId);
    }

    @Override
    public int save(ItripHotelOrder itripHotelOrder) {
        return itripHotelOrderMapper.insertSelective(itripHotelOrder);
    }

    @Override
    public int saveRecord(ItripHotelTempStore itripHotelTempStore) {
        return itripHotelTempStoreMapper.insertSelective(itripHotelTempStore);
    }
}
